#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Make directories full of stats and ldist alignments into directories full of json files
#Usage: jsonator.pl <stat_dir> <ldist_dir> <radar_dir> <hist_dir> <aln_dir>

my ($stat_dir, $ldist_dir, $radar_dir, $hist_dir, $aln_dir) = @ARGV;
chomp $aln_dir;
my @prefixes;
mkdir($radar_dir);
mkdir($hist_dir);
mkdir($aln_dir);
foreach my $file (`ls $stat_dir`) {
	chomp $file;
	my $prefix = [split(/\./, $file)]->[0];
	if(-e "$ldist_dir/$prefix.fasta.s.ldist") {
		push(@prefixes, $prefix);
		if(! -e "$aln_dir/$prefix.aln.jsonc") {
			`./ldist2json.pl $ldist_dir/$prefix.fasta.s.ldist > $aln_dir/$prefix.aln.jsonc`;
		}
		`./stats2json.pl $stat_dir/$file`;
		`mv $prefix.hist.jsonc $hist_dir/$prefix.hist.jsonc`;
		`mv $prefix.radar.jsonc $radar_dir/$prefix.radar.jsonc`;
	}
}
